package com.bdqn.rabbitmqporducer1.service;

import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Service;

import java.io.IOException;
import java.util.Map;

//@Service
//@RabbitListener(queues = "ConfirmQueue")
public class ConfrimReceiver {
    @RabbitHandler
    public void process(Map ReceiveMessage, Message message, Channel channel) throws IOException {
        try {
            System.out.println("消费消息：" + ReceiveMessage);
            channel.basicAck(message.getMessageProperties().getDeliveryTag(), true);
            System.out.println("消费消息确认" + message.getMessageProperties().getConsumerQueue() + ",接收到了回调方法");
        } catch (Exception e) {
            channel.basicNack(message.getMessageProperties().getDeliveryTag(), false, true);
            System.out.println("尝试重发：" + message.getMessageProperties().getConsumerQueue());
            channel.basicReject(message.getMessageProperties().getDeliveryTag(), true);
        }
    }
}
